package com.lin.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.mapper.DishMapper;
import com.lin.mapper.Plus.DishMapperPlus;
import com.lin.pojo.Dish;
import com.lin.response.CommonResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DishService extends ServiceImpl<DishMapperPlus, Dish> {
    @Autowired
    private DishMapper dishMapper;


    public CommonResp page(Integer pageNum,Integer pageSize,Integer type,String name){
        pageNum=(pageNum-1)*pageSize;
        name = "%"+name+"%";
        Map<String,Object> res = new HashMap<>();
        Integer total = dishMapper.SelectCount_ByName(type,name);
        List<Dish> data = dishMapper.Select_ByType(pageNum,pageSize,type,name);
        res.put("data",data);
        res.put("total" , total);

        CommonResp< Map<String,Object> > commonResp = new CommonResp();
        commonResp.setContent(res);
        commonResp.setSuccess(true);
        commonResp.setMessage("查找成功。");
        return commonResp;
    }

    /*********************** 管理端 *********************************/
    public CommonResp echarts(Integer type){
        List<Integer> popularity = dishMapper.SelectPopularity_ByType(type);
        List<String> dish = dishMapper.SelectDish_ByType(type);
        Map<String,Object> res = new HashMap<>();
        res.put("popularity",popularity);
        res.put("dish",dish);
        CommonResp< Map<String,Object> > commonResp = new CommonResp<>();
        commonResp.setContent(res);
        commonResp.setSuccess(true);
        commonResp.setMessage("查询图表所需数据成功。");
        return commonResp;
    }
    /*********************** 管理端 *********************************/
}
